﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using WeiTalk.SinaEntities.Status;
using System.Collections.Generic;
using RestSharp;
using WeiTalk.OAuth;

namespace WeiTalk.Interfaces.Sina
{
    public class StatusAPIs:WeiBoAPIs
    {
        const string FriendsTimeLineUrl = "https://api.weibo.com/2/statuses/friends_timeline.json";
        const string RepostByMeUrl = "https://api.weibo.com/2/statuses/repost_by_me.json";
        const string MentionsUrl = "https://api.weibo.com/2/statuses/mentions.json";
        public StatusAPIs(RestClient client) : base(client) { }

        /// <summary>
        /// http://open.t.sina.com.cn/wiki/2/statuses/friends_timeline
        /// </summary>
        /// <param name="callback"></param>
        /// <param name="page"></param>
        /// <param name="feature"></param>
        /// <param name="sinceID"></param>
        /// <param name="maxID"></param>
        /// <param name="base_app"></param>
        /// <param name="trim_user"></param>
        public void GetFriendsTimeLine(Action<IRestResponse<Entity>> callback, int page = 1, int feature = 0, string since_id = "0", string max_id = "0", int base_app = 0, int trim_user = 0)
        {
            RestRequest request = new RestRequest(FriendsTimeLineUrl, Method.GET);
            request.AddParameter("source", Utility.ConsumerKey);
            request.AddParameter("access_token", Utility.AccessToken.Token);
            request.AddParameter("count", Constant.WeiBoCount);
            request.AddParameter("feature", feature);
            request.AddParameter("page", page);
            request.AddParameter("since_id", since_id);
            request.AddParameter("max_id", max_id);
            request.AddParameter("base_app", base_app);
            request.AddParameter("timestamp", Guid.NewGuid().ToString());
            Client.ExecuteAsync<Entity>(request, callback);
        }

        /// <summary>
        /// http://open.t.sina.com.cn/wiki/2/statuses/repost_by_me
        /// </summary>
        /// <param name="callback"></param>
        /// <param name="since_id"></param>
        /// <param name="max_id"></param>
        /// <param name="count"></param>
        /// <param name="page"></param>
        public void GetReportByMe(Action<IRestResponse<Entity>> callback, int since_id = 0, int max_id = 0, int count = 50, int page = 1)
       {
           RestRequest request = new RestRequest(FriendsTimeLineUrl, Method.GET);
           request.AddParameter("source", Utility.ConsumerKey);
           request.AddParameter("access_token", Utility.AccessToken.Token);
           request.AddParameter("count", Constant.WeiBoCount);
           request.AddParameter("page", page);
           request.AddParameter("since_id", since_id);
           request.AddParameter("max_id", max_id);
           request.AddParameter("timestamp", Guid.NewGuid().ToString());
           Client.ExecuteAsync<Entity>(request, callback);
       }

        /// <summary>
        /// https://api.weibo.com/2/statuses/mentions.json
        /// </summary>
        /// <param name="callback"></param>
        /// <param name="since_id">若指定此参数，则返回ID比since_id大的微博（即比since_id时间晚的微博），默认为0。</param>
        /// <param name="max_id">若指定此参数，则返回ID小于或等于max_id的微博，默认为0。</param>
        /// <param name="page">返回结果的页码，默认为1。</param>
        /// <param name="filter_by_author">作者筛选类型，0：全部、1：我关注的人、2：陌生人，默认为0。</param>
        /// <param name="filter_by_source">来源筛选类型，0：全部、1：来自微博、2：来自微群，默认为0。</param>
        /// <param name="filter_by_type">原创筛选类型，0：全部微博、1：原创的微博，默认为0。</param>
        /// <param name="trim_user">返回值中user字段开关，0：返回完整user字段、1：user字段仅返回user_id，默认为0。</param>
        public void GetMentions(Action<IRestResponse<Entity>> callback, string since_id = "0", string max_id = "0", int page = 1, int filter_by_author = 0, int filter_by_source = 0, int filter_by_type = 0, int trim_user = 0)
        {
            RestRequest request = new RestRequest(MentionsUrl, Method.GET);
            request.AddParameter("source", Utility.ConsumerKey);
            request.AddParameter("access_token", Utility.AccessToken.Token);
            request.AddParameter("count", Constant.WeiBoCount);
            request.AddParameter("page", page);
            request.AddParameter("since_id", since_id);
            request.AddParameter("max_id", max_id);
            request.AddParameter("filter_by_author", filter_by_author);
            request.AddParameter("filter_by_source", filter_by_source);
            request.AddParameter("filter_by_type", filter_by_type);
            request.AddParameter("trim_user", trim_user);
            request.AddParameter("timestamp", Guid.NewGuid().ToString());
            Client.ExecuteAsync<Entity>(request, callback);
        }
    }
}
